/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import util.Data_variante;
import util.HTMLFilter;
/**
 *
 * @author dragonboy
 */
public class content_comment extends HttpServlet {

    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    private List<String> process_index_log(File _indexPath){
        List<String> list_date = new ArrayList<String>();
        File [] listfile = _indexPath.listFiles();
        for (int i = 0; i < listfile.length; i++) {
            if(!list_date.contains(listfile[i].getName().toString()))
            { 
                list_date.add(listfile[i].getName().toString());
            }
        }
        return list_date; 
    }
    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
        File indexDir = new File(Data_variante.dir_index);
        List<String> list_date = process_index_log(indexDir);
        Collections.sort(list_date);
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            //show content_comment
            out.println("<div id=\"content-comment\">"
                    + "<div id=\"content-header\">"
                    + "Content filter &gt; <b>Comment</b>"
                    + "</div>"
                    + "<div id=\"content-body\">"
                    + "<div id=\"content-form\">"
                    + "<div id=\"header-tip\" style=\"color: red; font-size: 13px; margin-left: 200px;\"></div>"
                    + "<form name=\"SearchContentComment\" action=\"Comment_show\" method=\"POST\" onsubmit=\"xmlhttpPost(\'Comment_show\', \'SearchContentComment\', \'content-action\', \'\'); return false;\">"
                    + "<table id=\"comment-table\" cellspacing=\"10\">"
                    + "<tbody>");
            
            //show choosingDate_form
            out.println("<tr class=\"row\">"
                    +"<td class=\"col1\">"+ Data_variante.SearchForm_Date+"</td>"
                    +"<td class=\"col2\">"
                    +"<select name=\"date\" class=\"form-content-select\">");
            
            //todo decision how many day in log data
            for(int c = 0;c < list_date.size(); c++){
                if( c == 0) out.println("<option value=\""+ list_date.get(c) + "\" selected=\"selected\">" + list_date.get(c) + "</option>");
                else out.println("<option value=\""+ list_date.get(c) + "\">" + list_date.get(c) + "</option>");
            }
            out.println("</select>"          
                        +"</td>"
                        +"</tr>");
            
            //show choosingApp_form
            out.println( "<tr class=\"row\">"
                    + "<td class=\"col1\">"+ Data_variante.SearchForm_App+"</td>"
                    + "<td class=\"col2\">"
                    + "<select name=\"app\" class=\"form-content-select\" id=\"select-app\">"
                    + "<option value=\"All\">All</option>"
                    + "<option value=\"16\" Disabled>123Mua (Product)</option>"
                    + "<option value=\"3\" Disabled>Album</option>"
                    + "<option value=\"1\" Disabled>Blog</option>"
                    + "<option value=\"4\" Disabled>Feed</option>"
                    + "<option value=\"20\" Disabled>Link</option>"
                    + "<option value=\"21\" Disabled>Live</option>"
                    + "<option value=\"19\" Disabled>Mp3-Playlist (Product)</option>"
                    + "<option value=\"17\" Disabled>Mp3-Song (Product)</option>"
                    + "<option value=\"18\" Disabled>Mp3-Video (Product)</option>"
                    + "<option value=\"2\" Disabled>Photo</option>"
                    + "<option value=\"5\" Disabled>Q&amp;A (Product)</option>"
                    + "</select>"
                    + "</td>"
                    + "</tr>");
            //show chosingtype_form
            out.println("<tr class=\"row\">"
                    + "<td class=\"col1\">"+ Data_variante.SearchForm_Type +"</td>"
                    + "<td class=\"col2\">"
                    + "<select name=\"Type\" class=\"form-content-select\" id=\"select-type\">"
                    + "<option value=\"3\">Bad</option>"
                    + "<option value=\"4\">Unsured Polictics</option>"
                    + "<option value=\"5\">Unsured Common</option>"
                    + "<option value=\"0\">Normal</option>"
                    + "</select>"
                    + "</td>"
                    + "</tr>");
            //show search button
            out.println("<tr class=\"row\">"
                    +"<td class=\"col1\"></td>"
                    +"<td class=\"col2\">"
                    +"<input type=\"submit\" value=\"Search\" name=\"Search\" class=\"form-content-submit\">"
                    +"</td>"
                    +"</tr>"
                    +"</tbody></table>"
                    +"</form>"
                    +"</div>"
                    +"<br class=\"clear-all\">"
                    +"<div id=\"content-action\">"
                    +"<div id=\"header-tip\"></div>"
                    +"<form name=\"HanderContentComment\" action=\"/submit_action\" method=\"POST\" onsubmit=\"xmlhttpPost(\'submit_action\', \'HanderContentComment\', \'content-action\', \'\'); return false;\">"
                    +"Total: 0                                <br class=\"clear-all\">"
                    +"<br class=\"clear-all\">"
                    +"<table id=\"content-action-table\" cellpadding=\"0\" cellspacing=\"0\">"
                    +"<thead>"
                    +"<tr>"
                    +"<th class=\"table-the-first\">"+ Data_variante.table_col1_name +"</th>"
                    +"<th class=\"table-1\">"+ Data_variante.table_col2_name +"</th>"
                    +"<th class=\"table-6\">"+ Data_variante.table_col7_name +"</th>"
                    +"<th class=\"table-7\">"+ Data_variante.table_col8_name +"</th>"
                    +"<th class=\"table-2\">"+ Data_variante.table_col3_name +"</th>"
                    +"<th class=\"table-3\">"+ Data_variante.table_col4_name("3") +"&nbsp;</th>"
                    +"<th class=\"table-4\">"+ Data_variante.table_col5_name("3") +"&nbsp;</th>"
                    +"<th class=\"table-5\">Post time</th>"
                    +"<th class=\"table-6\">"+ Data_variante.table_col7_name +"</th>"
                    +"</tr>"
                    +"</thead>"
                    +"<tbody id=\"table-body\">"
                    +"</tbody>"
                    +"</table>"
                    +"<br class=\"clear-all\">"
                    +"<br class=\"clear-all\">"
                    +"</form>"
                    +"<div class=\"pagination\">"
                    +"</div>"
                    +"</div>"
                    +"<div id=\"content-footer\">"
                    +"</div>"
                    +"</div>"
                    +"</div></div>"
               );
        } finally {            
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
